package com.tedu.ivos.vehicle.controller;


import com.tedu.ivos.base.response.JsonResult;
import com.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import com.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import com.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import com.tedu.ivos.vehicle.service.VehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "车辆管理")
@Slf4j
@RestController
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;
    @ApiOperation(value = "查询车辆信息")
    @GetMapping("/select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery) {
        log.info("查询车辆信息，参数：{}", vehicleQuery);
        List<VehicleVO> list=vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(list);
    }

    @ApiOperation(value = "车辆信息保存功能/修改更新")
    @PostMapping("/save")
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam) {
        log.debug("车辆信息保存功能/修改更新，参数：{}", vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }
    @ApiOperation(value = "删除车辆信息")
    @PostMapping("/delete/{id}")
    public JsonResult deleteVehicle(@PathVariable Long id) {
        log.debug("删除车辆信息，参数：{}", id);
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }

    @ApiOperation(value = "解绑车辆信息")
    @PostMapping("/unbind/{id}")
    public JsonResult unbindVehicle(@PathVariable Long id) {
        log.debug("解绑车辆信息，参数：{}", id);
        vehicleService.unbindVehicle(id);
        return JsonResult.ok();
    }

    @ApiOperation(value = "车辆信息绑定电子围栏")
    @PostMapping("/bind/{id}/{geofenceId}")
    public JsonResult bindVehicle(@PathVariable Long id, @PathVariable Long geofenceId) {
        log.debug("车辆信息绑定电子围栏，参数：{}", id);
        vehicleService.bindVehicle(id,geofenceId);
        return JsonResult.ok();
    }

}
